require('libs/weapp-adapter/index');
require('./flconsts.js');
require('utils/ald-game.js');
var Parser = require('libs/xmldom/dom-parser');
window.DOMParser = Parser.DOMParser;
require('libs/wx-downloader.js');
require('src/settings');
var settings = window._CCSettings;
require('main');
require(settings.debug ? 'cocos2d-js.js' : 'cocos2d-js-min.js');
require('./libs/engine/index.js');

// Adjust devicePixelRatio
cc.view._maxPixelRatio = 3;

wxDownloader.REMOTE_SERVER_ROOT = "";
wxDownloader.SUBCONTEXT_ROOT = "";
var pipeBeforeDownloader = cc.loader.subPackPipe || cc.loader.md5Pipe || cc.loader.assetLoader;
cc.loader.insertPipeAfter(pipeBeforeDownloader, wxDownloader);

if (cc.sys.browserType === cc.sys.BROWSER_TYPE_WECHAT_GAME_SUB) {
    var _WECHAT_SUBDOMAIN_DATA = require('src/subdomain.json.js');
    cc.game.once(cc.game.EVENT_ENGINE_INITED, function () {
        cc.Pipeline.Downloader.PackDownloader._doPreload("WECHAT_SUBDOMAIN", _WECHAT_SUBDOMAIN_DATA);
    });

    require('./libs/sub-context-adapter');
}
else {
    // Release Image objects after uploaded gl texture
    cc.macro.CLEANUP_IMAGE_CACHE = true;
}

// 启用抗锯齿
cc.macro.ENABLE_WEBGL_ANTIALIAS = true;

wxDownloader.init();

// 接入pre-config
const launchOptions = wx.getLaunchOptionsSync() || {};
wx.request({
	url: window.HOST + '/api/config/pre-config',
	data: {},
	header: {
        scene: launchOptions.scene,
        'client-ver': window.APP_VERSION
    },
    method: 'GET',
    success: (res) => {
        if (typeof res.data === 'string') { res.data = JSON.parse(res.data); }
        console.log('pre-config', res.data);
        window.reviewSwitch = res.data.reviewSwitch;
        window.eReviewSwitch = res.data.eReviewSwitch;
        window.uiPattern = res.data.uiPattern;
        window.isShowBox = res.data.isShowBox;
        window.isShowBoxBySceneTag = res.data.isShowBoxBySceneTag;
        window.isHideGameBoxButton = res.data.isHideGameBoxButton || 0;

        window.boot();
        
    },
    fail: (err) => {
        console.log(err);
        window.reviewSwitch = window.eReviewSwitch = 1;
        window.uiPattern = 0;
        
        window.boot();
    },
    complete: () => {
    },
});
